package tn.orange.canreminder.adapter;

import java.util.List;

import tn.orange.canreminder.R;
import tn.orange.canreminder.model.Opinion;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class OpinionAdapter extends BaseAdapter {

	private Context context;
	private List<Opinion> opinions;
	private LayoutInflater mInflater;

	public OpinionAdapter(Context context, List<Opinion> opinions) {
		super();
		mInflater = LayoutInflater.from(context);
		this.context = context;
		this.opinions = opinions;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return opinions.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return opinions.get(position);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {

		ViewHolder holder;

		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.opinion_item, null);
			holder = new ViewHolder();
			holder.article = (TextView) convertView
					.findViewById(R.id.opinion_item_article);
		
			holder.username = (TextView) convertView
					.findViewById(R.id.opinion_item_username);

			Opinion opinion = opinions.get(position);

			holder.article.setText(opinion.getArticle());
			holder.username.setText(opinion.getUsername());
		

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		return convertView;
	}

	static class ViewHolder {
		TextView username;
		TextView article;

	}

}
